/*******************************************************************************
 *
 *    Copyright (c) Dolphin Browser
 *
 *    ViewTest
 *
 *    ScrollPageView
 *    TODO File description or class description.
 *
 *    @author: derron
 *    @since:  2010-3-8
 *    @version: 1.0
 *
 ******************************************************************************/
package com.sdk.widget.threescreen.scrollview;

import com.sdk.widget.threescreen.scrollview.ScrollableView.WorldScrollProvider;

import android.content.Context;
import android.util.AttributeSet;
import android.view.MotionEvent;
import android.view.View;
import android.widget.FrameLayout;

public class ScrollPageView extends FrameLayout implements WorldScrollProvider {
    private int pageHeight;
    private int pageNumber;
    private int pageWidth;
    private WorldScrollProvider mWorldScrollProvider;
    public static final String TAG_WORLD_SCROLL_PROVIDER = "WorldScrollProvider";

    public ScrollPageView(Context context) {
        super(context);
        init(context);
    }

    public ScrollPageView(Context context, AttributeSet attrs) {
        super(context, attrs);
        init(context);
    }

    private void init(Context context){
        setFocusable(true);
        setVerticalScrollBarEnabled(false);
        setHorizontalScrollBarEnabled(false);
    }

    @Override
    public boolean dispatchTouchEvent(MotionEvent paramMotionEvent) {
        try {
            return super.dispatchTouchEvent(paramMotionEvent);
        } catch (Exception e) {

        }
        return false;
    }

    public int getPageNumber() {
        return this.pageNumber;
    }

    @Override
    protected void onMeasure(int paramInt1, int paramInt2) {

        int k = View.MeasureSpec.makeMeasureSpec(pageWidth,
                MeasureSpec.EXACTLY);
        int l = View.MeasureSpec.makeMeasureSpec(pageHeight,
                MeasureSpec.EXACTLY);
        super.onMeasure(k, l);
    }

    public void setPageDimension(int pageWidth, int pageHeight) {
        this.pageWidth = pageWidth;
        this.pageHeight = pageHeight;
    }

    public void setPageNumber(int paramInt) {
        this.pageNumber = paramInt;
    }

    public void setWorldScrollProvider(WorldScrollProvider worldScrollProvider) {
        mWorldScrollProvider = worldScrollProvider;
    }

    @Override
    public boolean shouldWorldScroll(int x, int y,int velocityX,int velocityY) {
        if(null == mWorldScrollProvider){
            return true;
        }
        else {
            return mWorldScrollProvider.shouldWorldScroll(x, y, velocityX, velocityY);
        }
    }

}
